import java.util.Iterator;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import friendShips.User;


@Path("/updateMyLocation/{myUserName}/{location}")

public class UpdateMyLocation {
	@GET
	@Produces("text/html")
	public String getUser(@PathParam("myUserName") String myUserName ,@PathParam("location") String location) {
		{
			SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); 
			Session session = sessionFactory.openSession();
			UserManager manager = new UserManager(session); 
			Query query = session.createQuery("from User user where user.email = :newEmail");
			query.setParameter("newEmail", myUserName);
			
			List <User>list = query.list();
			Iterator<User> it=list.iterator();
			
			User tempUser= new User();
			tempUser=it.next();
			
			tempUser.setLocation(location);
			manager.updateUser(tempUser);
			session.flush();
			
			return "GOOD";
		}
	}
}

